<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>

    <title>我的送检单</title>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <link rel="icon" href="favicon.ico" />

    <!-- table导出成excel 不用-->
    <!-- <script src="static/manage-sys/js/table2excel.js"></script> -->

    <!--[if lt IE 9]>
    <script src="js/bootstrap/html5shiv.min.js"></script>
    <script src="js/bootstrap/respond.min.js"></script>
    <![endif]-->
    <!--页面加载进度条-->


    <link href="css/pace/dataurl.css" rel="stylesheet" />
    <link rel="stylesheet" type="text/css" href="add-sample/easyui/themes/ui-cupertino/easyui.css" />
    <link rel="stylesheet" type="text/css" href="add-sample/easyui/themes/icon.css" />
    <link rel="stylesheet" type="text/css" href="add-sample/css/icon.css" />
    <link rel="stylesheet" type="text/css" href="add-sample/css/uims.css" />
    <link rel="stylesheet" type="text/css" href="add-sample/css/temp.css" />

    <link href="css/bootstrap.min.css" rel="stylesheet" />
    <link href="css/font-awesome.min.css" rel="stylesheet" />
    <link href="css/default.css" rel="stylesheet" type="text/css" />

    <script src="js/jquery.min.js"></script>
    <script type="text/javascript" src="add-sample/easyui/jquery.min.js"></script>
    <script src="js/jquery.hammer/hammer.min.js"></script>
    <script src="js/jquery.hammer/jquery.hammer.js"></script>

    <script type="text/javascript" src="add-sample/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="add-sample/easyui/locale/easyui-lang-zh_CN.js"></script>


    <script src="js/pace/pace.min.js" type="text/javascript"></script>
    <script src="js/jquery.scrolltopcontrol/scrolltopcontrol.js" type="text/javascript"></script>
    <script src="js/jquery.extend.js" type="text/javascript"></script>
    <script src="js/default.js" type="text/javascript"></script>
    <script src="js/bootstrap/bootstrap.min.js" type="text/javascript"></script>
    <script src="js/bootstrap/bootstrap-table.min.js" type="text/javascript"></script>
    <script src="js/bootstrap/bootstrap-table-zh-CN.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="add-sample/js/dataGridCellTip.js"></script>
    <script type="text/javascript" src="add-sample/js/validate.js"></script>
    <script type="text/javascript" src="add-sample/js/json2.js"></script>
    <script type="text/javascript" src="add-sample/js/sampleCommon.js"></script>
    <script type="text/javascript" src="add-sample/js/template.js"></script>
    <!--<script type="text/javascript" src="add-sample/js/deaf.js"></script>-->
    <!-- 下拉菜单 -->
    <link href="./css/bootstrap-select/bootstrap-select.min.css" rel="stylesheet" />
    <script src="./js/bootstrap-select/bootstrap-select.min.js"></script>
    <script src="./js/bootstrap-select/i18n/defaults-zh_CN.min.js"></script>
    <script src="./js/bootstrap-select/bootstrap-select-custom.js"></script>

    <script src="js/fileServer.js"></script>
    <!-- artTemplate 模板引擎 -->
    <script src="js/template-web.js" type="text/javascript"></script>
    <!-- 送检单导出操作-->
    <script src="js/exportTable.js"></script>

    <style>

        .table-wrapper panel-noscroll .panel datagrid easyui-fluid{height:100%;width:100%}
        .coupon-box {
            height: 120px;
            text-align: center;
            line-height: 120px;
            border: 1px dashed #2e85b8;
            font-size: 24px;
            color: #cecece;
            margin-top: 30px;
            cursor: pointer;
            background: #fff;
        }

        .coupon-item {
            width: 80%;
            box-shadow: 2px 2px 5px #f2f2f2, -2px -2px 5px #f2f2f2;
            border-bottom: 1px solid #eee;
            display: flex;
            margin: 10px auto;
            flex-direction: row;
        }

        .coupon-item .btn {
            display: block;
            margin: 10px;
            width: 60px;
            padding: 0;
            height: 28px;
            line-height: 28px;
            text-align: center;
            background: #45b4f5;
            color: #fff;
            /* outline: none; */
            border-color: transparent;
        }

        .coupon-item .content-wrapper {
            flex: 1;
            padding: 10px;
        }

        .coupon-item .content-wrapper .name {
            font-size: 14px;
            font-weight: 400;
            color: rgba(0, 0, 0, 0.85);
        }

        .coupon-item .content-wrapper .desc {
            font-size: 12px;
            margin-top: 4px;
            color: rgba(0, 0, 0, 0.55);
        }

        .search-box input {
            display: inline-block;
            flex: 1;
            height: 33px;
            line-height: 33px;
            padding-left: 6px;
            /* border-color: transparent; */
            outline: none;
            box-shadow: none;
            /* border: 0; */
            border: 1px solid #7bcdf8;
        }

        .search-box button {
            width: 80px;
            background: #7bcdf8;
            outline: none;
            border: 1px solid #7bcdf8;
            color: #fff;
        }

        .empty-coupon {
            text-align: center;
            line-height: 42px;
            height: 42px;
            font-size: 18px;
            color: rgba(0, 0, 0, 0.45);
        }

        .search-params {
            border-bottom: 1px solid #dedede;
            margin: 20px 16px;
        }

        .panel-body {
            position: relative;
            border-left: 0 !important;
            padding: 15px !important;
            overflow: initial;
        }

        .search-row {
            display: flex;
            flex-direction: row;
        }

        .search-item {
            flex: 1;
            display: flex;
            flex-direction: row;
            margin-left: 30px;
        }

        .search-item:first-child {
            margin-left: 0;
        }

        .search-item>label {
            display: inline-block;
            min-width: 80px;
            letter-spacing: 2px;
            text-align: center;
            height: 33px;
            line-height: 33px;
        }

        .search-item>.value {
            display: inline-block;
            flex: 1;
            height: 33px;
            line-height: 33px;
        }

        div.btn-operate {
            margin: 20px 16px;
            text-align: center;
        }

        div.btn-operate>button {
            display: inline-block;
            width: 120px;
            margin: 6px;
            margin-left: 30px;
        }

        div.btn-operate>button:first-child {
            margin-left: 0;
        }

        input {
            outline: none !important;
        }


        .params-warpper {
            display: flex;
            flex-direction: row;
            padding-right: 200px;
        }

        #search-btn {
            position: absolute;
            right: 88px;
            top: 50%;
            transform: translateY(-50%);
            width: 90px;
        }

        #reset-btn {
            position: absolute;
            right: 16px;
            top: 50%;
            transform: translateY(-50%);
            width: 50px;
        }

        .params-warpper .params-item {
            flex: 1;
            display: flex;
            flex-direction: row;
            margin-top: 10px;
        }

        .params-warpper .params-item label {
            display: inline-block;
            min-width: 120px;
            line-height: 34px;
            text-align: right;
            letter-spacing: 2px;
        }

        .params-warpper .params-item .value {
            flex: 1;
        }

        .add-sample {
            margin: 10px;
        }

        .maincontent {
            height:800px;
            display: flex;
            flex-direction: column;
            overflow:auto;
        }

        .table-wrapper {
            flex: 1;
            display: flex;
            flex-direction: column;
            overflow-y: scroll;
        }

        .maincontent {
            min-width: 1000px !important;
            overflow: hidden !important;
            overflow-x: scroll !important;
        }

        .split {
            line-height: 33px;
            height: 33px;
            display: inline-block;
            width: 20px;
            text-align: center;
        }

        input[type=checkbox],
        input[type=radio] {
            margin: auto;
        }

        .datagrid-row-selected {
            background: #fff;
        }
    </style>
</head>

<body  style="width:100%;height:100%;" >

<div class="maincontent">

    <!--我是主要内容-->
    <!--我是主要内容-->

    <div class="panel panel-default box-params">
        <div class="panel-heading">
            查询条件
        </div>
        <div class="panel-body form-group">
            <div class="params-warpper">
                <div class="params-item">
                    <label class="control-label">受检者姓名：</label>
                    <input type="text" placeholder="请输入受检者姓名" class="form-control value" id="sampleName" />
                </div>
                <div class="params-item">
                    <label class="control-label">送检单号：</label>
                    <input type="text" placeholder="请输入送检单号" class="form-control value" id="sampleId" />
                </div>
                <div class="params-item">
                    <label class="control-label">状态：</label>
                    <select type="text" class="form-control value" id="status">
                        <option value=''>请选择状态</option>
                        <option value="0">未推送</option>
                        <option value="1">已推送</option>
                        <!--<option value="2">推送失败</option>-->
                        <option value="3">已出报告</option>
                        <!--<option value="4">送检单失效</option>-->
                    </select>
                </div>
            </div>
            <div class="params-warpper">
                <div class="params-item">
                    <label class="control-label">送检医院：</label>
                    <select id="search-customer" class="selectpicker form-control value" data-live-search="true" data-max-options="1">
                    </select>
                </div>
                <div class="params-item">
                    <label class="control-label">检测类型：</label>
                    <select name="productName" id="productName" class="form-control value">
                        <option value="">请选择</option>
                        <option value="BS0001">产前血清学筛查</option>
                        <option value="BS0002">新生儿疾病筛查</option>
                    </select>
                </div>
                <div class="params-item">
                    <label class="control-label">免费券编码：</label>
                    <input type="text" placeholder="请输入免费券编码" class="form-control value" id="couponCode" />
                </div>
            </div>
            <div class="params-warpper">
                <div class="params-item">
                    <label class="control-label">受检者身份证：</label>
                    <input type="text" placeholder="请输入受检者身份证" class="form-control value" id="idCard" />
                </div>
                <div class="params-item">
                    <label class="control-label">区/县：</label>
                    <select name="search-country" id="search-country" class="form-control value"></select>
                </div>
                <div class="params-item">
                    <label class="control-label">街道：</label>
                    <select name="search-town" id="search-town" class="form-control value"></select>
                </div>
            </div>
            <div class="params-warpper">
                <div class="params-item">
                    <label class="control-label">检测结果：</label>
                    <select name="sampleResult" id="sampleResult" class="form-control value">
                        <option value="">请选择</option>
                        <option value="高风险">高风险</option>
                        <option value="低风险">低风险</option>
                        <option value="正常">正常</option>
                        <option value="异常">异常</option>
                    </select>
                </div>
                <div class="params-item">
                    <label class="control-label">扫码采样日期：</label>
                    <input type="text" placeholder="开始日期" class="form-control value" id="search-scan-start-time" onblur="(this.type='text')"
                           onfocus="(this.type='date')" />
                    <span class="split">~</span>
                    <input type="text" placeholder="结束日期" class="form-control value" id="search-scan-end-time" onblur="(this.type='text')" onfocus="(this.type='date')"
                    />
                </div>
                <div class="params-item">
                    <label class="control-label">收费类型：</label>
                    <select name="isCharge" id="isCharge" class="form-control value">
                        <option value="">请选择</option>
                        <option value="1">免费</option>
                        <option value="2">自费</option>
                    </select>
                </div>
            </div>
            <div class="params-warpper">
                <div class="params-item">
                    <label class="control-label">采血卡编号：</label>
                    <input type="text" placeholder="请输入采血卡编号" class="form-control value" id="inputbarCode" onclick="inputbarCodeDele()" onkeydown="whetherToSearch()"/>
                </div>
                <div class="params-item"></div>
                <div class="params-item"></div>
            </div>
            <button class="btn btn-primary" id="search-btn" onclick="toSearch()">查询</button>
        </div>
    </div>
    <div class="table-wrapper">

        <table id="sampleImport_mainTable" toolbar="#toolbar"></table>
    </div>
</div>

</div>

<a href="#top" id="goTop">
    <i class="fa fa-angle-up fa-3x"></i>
</a>


</body>
<script type="text/javascript">

    function callParent(title,url){

        window.parent.addTab(title,url);

    }

    function getJsonFromUrl() {
        var query = location.search.substr(1);
        var result = {};
        query.split("&").forEach(function (part) {
            var item = part.split("=");
            result[item[0]] = decodeURIComponent(item[1]);
        });
        return result;
    }

    //区县列表
    $.ajax({
        method: 'POST',
        url: '/csfy/intf.do',
        data: { method: 'getAddrsToAccess', parentId: 4301 },
        success: function (res) {
            var options = '<option value="">请选择</option>'
            if (res && res.code == 200) {
                (res.rows || []).forEach(countryItem => {
                    options += '<option value="' + countryItem.name + '">' + countryItem.name + '</option>';
                })
            }
            $('#search-country').html(options);
        }
    });

    $(function () {
        //街道
        $('#search-country').change(function () {
            var countryStr = $(this).val();//获得区县
            $.ajax({
                method: 'POST',
                url: '/csfy/intf.do',
                data: { method: 'getTownToUserAccess', name: countryStr },
                success: function (res) {
                    var options = '<option value="">请选择</option>'
                    if (res && res.code == 200) {
                        (res.rows || []).forEach(countryItem => {
                            options += '<option value="' + countryItem.name + '">' + countryItem.name + '</option>';
                        })
                    }
                    $('#search-town').html(options);
                }
            });
        });
    });

    //医院列表
    $.ajax({
        method: 'POST',
        url: '/csfy/intf.do',
        data: {
            method: 'getCustomers',
            addressCity: '长沙市',
        },
        success: function (res) {
            if (res && res.code == 200) {
                var customerList = res.rows || [];
                var customerOptions = '<option value="">请选择医院</option>';
                customerList.forEach(customer => {
                    customerOptions += '<option value="' + customer.customerCode + '">' + customer.customerName + '</option>';
                });
                $('#search-customer').html(customerOptions);
                $('.selectpicker').selectpicker('refresh');
            }
        }
    });

    //  请求获取所有样品种类
    $.ajax({
        method: 'POST',
        url: '/csfy/ws/getSampleTypeList.do',
        success: function (res) {
            var getData = JSON.parse(res);
            if(getData.code == 200){
                var sampleTypeList = getData.rows || [];
                var sampleTypeOptions = '<option value="">请选择</option>';
                sampleTypeList.forEach(sample => {
                    sampleTypeOptions += '<option value="' + sample.code + '">' + sample.name + '</option>';
                });
                $('#sampleType').html(sampleTypeOptions);
                $('.selectpicker').selectpicker('refresh');
            }


        },
        error: function (err) {
            alert("网络异常");
        }
    });

    $(".maincontent").height($("body").height() - 50);
    //获取搜索条件
    function getQueryParams() {

        var sampleName = $("#sampleName").val() || '';
        var sampleBaseId = $("#sampleId").val() || '';
        var status = $("#status").val() || '';
        var sendHospitalName = $("#search-customer option:selected").text() || '';
        if(sendHospitalName == "请选择医院"){
            sendHospitalName = "";
        }
        var productName = $("#productName").val() || '';
        if(productName == "请选择"){
            productName = "";
        }
        var couponCode = $("#couponCode").val() || '';
        var isCharge = $("#isCharge").val() || '';
        if(isCharge == "请选择"){
            isCharge = "";
        }

        var query = {};
        var sampleResult = $("#sampleResult").val();
        if (sampleResult != null && sampleResult != '' && sampleResult != '请选择') {
            query.resultAll = sampleResult;
        }
        var country = $("#search-country").val();
        if (country != null && country != '') {
            query.country = country;
        }
        var town = $("#search-town").val();
        if (town != null && town != '') {
            query.town = town;
        }
        if (sampleName != '') {
            query.sampleName = sampleName;
        }
        var barCodeNum =  $("#inputbarCode").val() || '';
        if (barCodeNum != null && barCodeNum != "" ){
            query.barCode = barCodeNum;
        }
        if (sampleBaseId != '') {
            query.sampleBaseId = sampleBaseId;
        }

        if (status != '') {
            query.pushStatus = status;
        }
        if (sendHospitalName != '') {
            query.sendHospitalName = sendHospitalName;
        }
        if (productName != '') {
            query.couponProductCode = productName;
        }
        if (isCharge != '') {
            query.isCharge = isCharge;
        }
        //
        if (couponCode != '') {
            query.couponCode = couponCode;
        }
        var idCard = $("#idCard").val();
        if (idCard != null && idCard != '') {
            query.idCard = idCard;
        }
        var searchStartTime = $("#search-scan-start-time").val();
        if (searchStartTime != null && searchStartTime != '') {
            query.createStartTime = searchStartTime + " 00:00:00";
        }
        var searchEndTime = $("#search-scan-end-time").val();
        if (searchEndTime != null && searchEndTime != '') {
            query.createEndTime = searchEndTime + " 23:59:59";
        }
        return query;
    }

    var deleBarCode = false;
    function inputbarCodeDele(){
        if (deleBarCode) {
            $("#inputbarCode").val("");
            deleBarCode = false;
        }
    }
    function whetherToSearch() {
        if(event.keyCode == "13") {
            toSearch();
            deleBarCode = true;
        }
    }
    //按条件搜索
    function toSearch() {
        $('#sampleImport_mainTable').datagrid('reload', getQueryParams());
    }
    //退出登录
    function logout() {
        $.ajax({
            url: '/csfy/dologout.do',
            method: 'POST',
            success: function (res) {
                if (JSON.parse(res).code == 200) {
                    window.location.href = "/csfy/index.do"
                }
            }
        })
    }
    //获取当前登录用户信息
    $(document).ready(function () {
        $.ajax({
            method: 'POST',
            url: '/csfy/intf.do',
            data: { method: 'getLoginUserInfo' },
            success: res => {
                if (res.code == 10086) {
                    alert("请重新登录！");
                } else {
                    if (res.code == 200) {
                        $(".username").html(res.rows.userName);
                    }
                }
            }
        })
    })

    //生成用户数据
    $('#sampleImport_mainTable').datagrid({
        url: '/csfy/intf.do?method=getSampleUploadBS&filterType=2',
        fit: true,
        rownumbers: true,
        pagination: true,
        singleSelect: false,
        striped: true,
        fitColumns: false,
        frozenColumns:
                [[
                    { field: 'ck', checkbox: 'false' }
                ]],
        columns: [[
            { field: 'info', title: '操作', align: 'center', formatter: showEdit },
            { field: 'sampleBaseId', title: '送检单号', align: 'center' },
            { field: 'barCode', title: '采血卡编号', align: 'center' },
            { field: 'sampleName', title: '受检者姓名', align: 'center' },
            { field: 'idCard', title: '身份证', align: 'center' },
            { field: 'couponCode', title: '券码', align: 'center' },
            { field: 'productName', title: '检测类型', align: 'center' },
            { field: 'isCharge', title: '收费类型', align: 'center', formatter: isCharge },
            { field: 'pushStatus', title: '推送状态', align: 'center', formatter: pushStatus },
            { field: 'resultTime', title: '报告获取时间', align: 'center' },
            { field: 'scannerHospital', title: '采血医院', align: 'center' },
            { field: 'createTime', title: '采样时间', align: 'center' },
            { field: 'inspectionAgencyName', title: '检测机构', align: 'center' },
            { field: 'country', title: '区县', align: 'center' },
            { field: 'town', title: '街道', align: 'center' },
            { field: 'pheResult', title: 'PHR检测', align: 'center' },
            { field: 'tshResult', title: 'TSH检测', align: 'center' },
            { field: 'ohpResult', title: '17_a_OHP检测', align: 'center' },
            { field: 'g6pdResult', title: 'G6PD检测', align: 'center' },
            { field: 'msmsResult', title: 'MSMS检测', align: 'center' },
            { field: 'resultAll', title: '检测结果', align: 'center' }
        ]],
        onLoadSuccess: function (data) {
            total = data.total
        }
    });
    //推送
    function toUpdata(sampleBaseId) {
        $.ajax({
            method: 'POST',
            async:false,
            url: '/csfy/intf.do?method=batchCallBSWebServicer&sampleBaseId='+ sampleBaseId ,
            success: function (res) {
                if(res.msg == "success"){
                    alert(res.rows.data.info);
                    window.location.reload();
                }else {
                    alert(res.msg);
                }
            }
        })
    }
    //获取
    function toGetdata(sampleBaseId) {
        $.ajax({
            method: 'POST',
            async:false,
            url: '/csfy/intf.do?method=batchCallBSWebServicer&sampleBaseId='+ sampleBaseId ,
            success: function (res) {
                if(res.msg == "success"){
                    alert(res.rows.data.info);
                    window.location.reload();
                }else {
                    alert(res.msg);
                }
            }
        })
    }
    //操作
    function showEdit(value, row) {
        var str = "";
        if(row.pushStatus == 0){
            str = '<a class="sample-edit" href="javascript:toUpdata(' + JSON.stringify(row.sampleBaseId).replace(/\"/g,"'") + ')" style="color:#337ab7;margin-right:10px;">推送</a>';
        }else if(row.pushStatus == 1){
            str =  '<a class="sample-edit" href="javascript:toGetdata(' + JSON.stringify(row.sampleBaseId).replace(/\"/g,"'") + ')" style="color:#337ab7">获取</a>';
        }
        return str;
    }
    //收费类型
    function isCharge(value, row) {
        if(value == 2){
            return "自费";
        }else {
            return "免费";
        }
    }
    //推送状态
    function pushStatus(value, row) {
        if(value == 0){
            return "未推送";
        }else if(value == 1){
            return "推送成功";
        }else if(value == 3){
            return "已获取结果";
        }
    }

</script>

<!-- 要导出的送检单table模板 -->
<script id="table" type="text/html">
    <table border="1" class="tables">
        <tr>
            {{each ths item i}}
            <th>{{item.fieldValue}}</th>
            {{/each}}
        </tr>
        {{each trs item i}}
        <tr>
            {{each item value i}}
            <td>{{value}}</td>
            {{/each}}
        </tr>
        {{/each}}
    </table>


    }


</script>


</html>